package com.gy.spring.mvc.controller;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.gy.spring.mvc.entity.User;
import com.gy.spring.mvc.service.UserService;

import java.util.List;

/**
 * TODO 用户控制器
 *
 * @author geYang
 * @date 2018-04-16
 */
@RestController
@RequestMapping("user")
public class UserController {

    @Autowired
    private UserService userService;

    /**
     * TODO 用户列表
     *
     * @return
     * @author geYang
     * @date 2018-04-16 11:37
     */
    @RequestMapping(value = "list", method = RequestMethod.GET)
    public Object list() {
        Page<Object> objects = PageHelper.startPage(1, 10);
        List listUser = userService.listUser();
        System.out.println(listUser);
        for (Object user : listUser) {
            System.out.println(user);
        }
        return listUser;
    }

    /**
     * TODO 用户详情
     *
     * @param id
     * @return
     * @author geYang
     * @date 2018-04-16 11:37
     */
    @RequestMapping(value = "get/{id}", method = RequestMethod.GET)
    public Object get(@PathVariable("id") int id) {
        return null;
    }

    /**
     * TODO 用户添加
     *
     * @param user
     * @return
     * @author geYang
     * @date 2018-04-16 11:37
     */
    @RequestMapping(value = "add", method = RequestMethod.POST)
    public Object add(User user) {
        return null;
    }

    /**
     * TODO 用户更新
     *
     * @param user
     * @return
     * @author geYang
     * @date 2018-04-16 11:36
     */
    @RequestMapping(value = "update", method = RequestMethod.POST)
    public Object update(User user) {
        return null;
    }

    /**
     * TODO 用户删除
     *
     * @param id
     * @return
     * @author geYang
     * @date 2018-04-16 11:37
     */
    @RequestMapping(value = "del/{id}", method = RequestMethod.POST)
    public Object del(@PathVariable("id") int id) {
        return null;
    }

    /**
     * TODO 回滚测试
     *
     * @throws Exception
     * @author geYang
     * @date 2018-04-16 11:38
     */
    @RequestMapping(value = "test", method = RequestMethod.GET)
    public void test() {
        userService.test();
    }

    /**
     * TODO 缓存测试
     *
     * @return
     * @author geYang
     * @date 2018-04-16 11:38
     */
    @RequestMapping(value = "testCache", method = RequestMethod.GET)
    public Object testCache() {
        return null;
    }

    @RequestMapping(value = "testCache2", method = RequestMethod.GET)
    public Object testCache2() {
        userService.listUser();
        userService.listUser();
        return userService.listUser();
    }

}
